package cst.neu.yuejian_31.activity;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.view.WindowManager;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;

import cst.neu.yuejian_31.Common.Constant;
import cst.neu.yuejian_31.R;

public class MasterVideoActivity extends BaseActivity {
    private VideoView mastervideoView;
    private String path="";
    private ProgressDialog dialog;
    private Context context;
    private String movie;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mastervideo);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);//设置屏幕方向为横向
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);//设置全屏
        getWindow().setFormat(PixelFormat.TRANSLUCENT);//透明
        mastervideoView=(VideoView)findViewById(R.id.mastervideoview);
        context=MasterVideoActivity.this;
        movie  = getIntent().getStringExtra("resid");//获取传递的资源id
        //获取传递的资源用户id
        path= Constant.MASTERVIDEO_URL +getIntent().getStringExtra("mastervideopath");//获取视频全路径
        dialog=ProgressDialog.show(MasterVideoActivity.this, "视频加载中...", "请您稍候");//进度条

        Uri uri = Uri.parse(path);
        mastervideoView.setMediaController(new MediaController(this));//媒体播放控制工具
        mastervideoView.setVideoURI(uri);//设置视频路径
        mastervideoView.setOnPreparedListener(new MyPlayerOnPreparedListener());//播放开始回调
        mastervideoView.setOnCompletionListener( new MyPlayerOnCompletionListener());//播放完成回调
        mastervideoView.requestFocus();// 让VideoView获取焦点
        mastervideoView.start();//开始播放
    }
    //自定义子类，监听视频准备好，消除加载对话框
    class MyPlayerOnPreparedListener implements MediaPlayer.OnPreparedListener {
        @Override
        public void onPrepared(MediaPlayer mp) {
            mastervideoView.setBackgroundColor(Color.argb(0, 0, 255, 0));
            dialog.dismiss();
        }
    }
    //自定义子类，监听播放完成，显示完成
    class MyPlayerOnCompletionListener implements MediaPlayer.OnCompletionListener {

        @Override
        public void onCompletion(MediaPlayer mp) {
            Toast.makeText( MasterVideoActivity.this, "播放完成", Toast.LENGTH_SHORT).show();
            //getSupportActionBar().show();
        }
    }
}
